//
//  CategoryCell.swift
//  SwiftUi
//
//  Created by xm on 02/09/2025.
//

import SwiftUI

struct CategoryCell: View {
    
    var categories: [CNLandmark]!
    var categoryName: String!
    
    var body: some View {
        VStack(alignment: .leading){
            Text(categoryName).font(.system(size: 18)).bold()
            ScrollView(.horizontal, showsIndicators: false){
                HStack( spacing: 15) {
                    ForEach(categories) { (landmark:CNLandmark) in
                        CategoryItem(landmark: landmark)
                        
                    }
                }
            }
        }.padding(15)
    }
}

struct CategoryItem: View {
    var landmark: CNLandmark
    
    var body: some View {
        NavigationLink(destination: CNLandmarkDetail(landmark: landmark) ){
            VStack(alignment: .leading){
                landmark.image
                    .resizable()
                    .scaledToFill()
                    .frame(width: 155, height: 155)
                    .clipped()
                    .cornerRadius(5)
                    .listRowInsets(EdgeInsets())
                
                Text(landmark.name)
                    .font(.caption)
                    .foregroundColor(.black)
            }
        }
        
        
    }
}

#Preview {
    CategoryCell(categories: Array(CN_landmarks.prefix(3)), categoryName: CN_landmarks[0].category)
}
